﻿package com.snakedickgames.common.sandy 
{
    import com.pblabs.engine.debug.Logger;
    import com.pblabs.engine.components.AnimatedComponent;
    import sandy.core.scenegraph.Node;
    import sandy.materials.Appearance;
    
    
    public class SandyNode extends AnimatedComponent 
    {
        public var nodeName:String;
        public var appearance:Appearance;
        
        protected var _scene:SandyScene3D;
        protected var _node:Node;
        protected var _inScene:Boolean = false;
                
        public function set node(value:Node):void
        {
            removeFromScene();
            _node = value;
            addToScene();
        }
        
        public function get node():Node
        {
            return _node;
        }
        
        override protected function onReset():void 
        {
            super.onReset();
            
            if (_node && appearance)
            {
                node.appearance = appearance;
            }
        }
        
        protected function addToScene():void
        {
            if (!_inScene && _node && scene)
            {
                scene.add(this);
                _inScene = true;
            }
        }
        
        protected function removeFromScene():void
        {
            if (!_inScene && _node && scene)
            {
                scene.remove(this);
                _inScene = false;
            }
        }
        
        public function set scene(value:SandyScene3D):void
        {
            removeFromScene();
            _scene = value
            addToScene();
        }
        
        public function get scene():SandyScene3D
        {
            return _scene;
        }
    }
}